package com.example.frank.test2;

import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.EditText;
import com.example.frank.test2.domain.ExcelInfo;

import org.json.JSONArray;

import java.io.InputStream;
import java.util.ArrayList;
import jxl.Sheet;
import jxl.Workbook;

/**
 * Created by Administrator on 2018/5/21.
 */

public class ImportAction extends Activity{
    EditText et;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_import_excel);
         et = findViewById(R.id.et);
        readExcel();
    }

    public  void readExcel(){
        ArrayList<ExcelInfo> list = new ArrayList<ExcelInfo>();
        AssetManager manage = getAssets();

        try {
            InputStream is = getAssets().open("test.xls");
            Log.i("lee",is.toString());
            //获得工作簿对象
            Workbook workbook = Workbook.getWorkbook(is);
            //获得第一个工作表
            Sheet sheet=  workbook.getSheet(0);
            //获得总共有多少行
            int rows = sheet.getRows();
            //得到所有的列
            int columns = sheet.getColumns();
            //遍历
            for (int i = 0;i<rows;i++){
                ExcelInfo excelInfo = new ExcelInfo();
                excelInfo.setUsername(sheet.getCell(0,i).getContents());
                excelInfo.setPassword(sheet.getCell(1,i).getContents());
                list.add(excelInfo);
            }

            System.out.print(list);

            Log.i("lee","结果是："+list);
        }catch(Exception e){
            e.printStackTrace();
        }

    }
}
